const dbConfig = require("../config/db-config.js");
const { Sequelize,Op } = require('sequelize');

// 数据库配置链接
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
    host: dbConfig.HOST,
    dialect: dbConfig.dialect,
    // operatorsAliases: 1,
    timezone: '+08:00', //东八时区（sequelize 存取时间是按照 UTC标准时间 ，而我们是处于东八区，所以要快8小时）
    define: {
        freezeTableName: true // 使用与模型名称相同的名称.
    },
    pool: {
        max: dbConfig.pool.max,
	    min: dbConfig.pool.min,
	    acquire: dbConfig.pool.acquire,
	    idle: dbConfig.pool.idle
    }
})

const db = {};
db.Sequelize = Sequelize;//引入
db.sequelize = sequelize;//实例
db.Op = Op; //操作符

// ========================= 用户 =========================
// 用户
db.users = require("./users/users-model.js")(sequelize, Sequelize);
// 用户-角色 关联模型
db.usersRoles = require("./users/users-roles-model.js")(sequelize, Sequelize);
// 评论
db.comments = require("./users/comments-model.js")(sequelize, Sequelize);
// 留言
db.message = require("./users/message-model.js")(sequelize, Sequelize);
// 回复
db.replies = require("./users/replies-model.js")(sequelize, Sequelize);
// 访客
db.visitor = require("./users/visitor-model.js")(sequelize, Sequelize);
// 用户-文章 点赞关联模型
db.likes = require("./users/users-article-likes-model.js")(sequelize, Sequelize);
// 弹幕
db.danmu = require("./users/danmu-model.js")(sequelize, Sequelize);

// ========================= 文章 =========================
// 标签
db.tags = require("./article/tags-model.js")(sequelize, Sequelize);
// 文章
db.article = require("./article/article-model.js")(sequelize, Sequelize);
// 文章-标签关联模型 
db.articleTags = require("./article/article-tags-model.js")(sequelize, Sequelize);
// 分类
db.sort = require("./article/sort-model.js")(sequelize, Sequelize);

// ========================= 系统 =========================
// 字典类别
db.sysDictType = require("./system/sys-dict-type-model.js")(sequelize, Sequelize);
// 字典数据
db.sysDictData = require("./system/sys-dict-data-model.js")(sequelize, Sequelize);
// 网站信息
db.website = require("./system/website-model.js")(sequelize, Sequelize);
// 文件
db.files = require("./system/files-model.js")(sequelize, Sequelize);
// 友链
db.friendLink = require("./system/friend-link-model.js")(sequelize, Sequelize);
// 菜单导航
db.menus = require("./system/menus-model.js")(sequelize, Sequelize);
// 角色
db.roles = require("./system/roles-model.js")(sequelize, Sequelize);
// 角色-菜单关联模型
db.rolesMenus = require("./system/roles-menus-model.js")(sequelize, Sequelize);
// 收藏夹
db.favorite = require("./system/favorite-model")(sequelize, Sequelize);

// ========================= 音乐 =========================
// 歌曲
db.songs = require("./music/songs-model.js")(sequelize, Sequelize);
// 歌词
db.lyrics = require("./music/lyrics-model.js")(sequelize, Sequelize);
// 艺术家
db.artist = require("./music/artist-model.js")(sequelize, Sequelize);
// 专辑
db.album = require("./music/album-model.js")(sequelize, Sequelize);
// 流派
db.genre = require("./music/genre-model.js")(sequelize, Sequelize);


//各个表的应用关系
module.exports = db;